/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    ListNode* deleteNode(ListNode* head, int val) {
        if(head==nullptr)return nullptr;
        if(head->val==val)return head->next;
        ListNode* cur=head->next;
        ListNode* ptr=head;
        while(cur){
            //节点值相等，删除节点
            if(cur->val==val){
                ptr->next=cur->next;
                break;
            }else{
                ptr=cur;
                cur=cur->next;
            }
        }
        return head;
    }
};